package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAccountTraceMapper;
import com.qf.pojo.DtsAccountTrace;
import com.qf.service.DtsAccountTraceService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * projectName:workspace_6
 * author:hyn
 * time:2021/11/30 23:09
 * description:
 */
@Service
public class DtsAccountTraceServiceImpl implements DtsAccountTraceService {
    @Autowired
    private DtsAccountTraceMapper accountTraceMapper;
    @Override
    public IPage<DtsAccountTrace> findAll(String username, String mobile, Integer limit, Integer page, String sort, String order, Integer[] statusArray) {
        IPage<DtsAccountTrace> ipage = new Page(page,limit);
        QueryWrapper<DtsAccountTrace> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(username)){
            wrapper.like("user_id",username);
        }
        if(!StringUtils.isEmpty(mobile)){
            wrapper.like("mobile",mobile);
        }
        if(statusArray != null && statusArray.length > 0){

            wrapper.in("status",statusArray);
        }
        if("asc".equals(order)){
            wrapper.orderByAsc(sort);
        }else{
            wrapper.orderByDesc(sort);
        }
        IPage<DtsAccountTrace> p = accountTraceMapper.selectPage(ipage, wrapper);
        return p;
    }

    @Override
    public Object saveStatus(DtsAccountTrace accountTrace) {
        accountTrace.setUpdateTime(new Date());
        int i = accountTraceMapper.updateById(accountTrace);
        if(i > 0 ){
            return ResponseUtil.ok();
        }
        return ResponseUtil.fail(-1,"审批失败");
    }
}
